package com.asion.qkan.ui.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.asion.qkan.R;
import com.asion.qkan.ui.util.LoadingDailog;
import com.asion.qkan.utils.changeTheme.ThemeChangeUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ContentActivity extends AppCompatActivity implements View.OnClickListener {

    @BindView(R.id.content_back)
    ImageView contentBack;
    @BindView(R.id.content_title)
    TextView contentTitle;
    @BindView(R.id.content_all)
    TextView contentAll;
    @BindView(R.id.content_webview)
    WebView contentWebview;
    @BindView(R.id.activity_content)
    LinearLayout activityContent;
    private Bundle extras;
    private String tag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeChangeUtil.changeTheme(this);
        setContentView(R.layout.activity_content);
        ButterKnife.bind(this);
        LoadingDailog.showDialogForLoading(this);
        Intent intent = getIntent();
        extras = intent.getBundleExtra("bundle");
        tag = extras.getString("tag");
        String url = extras.getString("url");
        String subtitle = extras.getString("subtitle");
        contentAll.setOnClickListener(this);
        contentBack.setOnClickListener(this);
        contentTitle.setText(subtitle);
        contentWebview.loadUrl(url);
        LoadingDailog.cancelDialogForLoading();
    }

   public static void startAction(Activity activity, Bundle bundle) {
        Intent intent = new Intent(activity, ContentActivity.class);
        intent.putExtra("bundle", bundle);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.fade_in,
                R.anim.fade_out);
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.content_back:
                finish();
                break;
            case R.id.content_all://全集的点击事件
                if(tag == null){
                    //跳AllActivity
                    AllActivity.startAction(this,extras);
                }else{
                    finish();
                }

                break;
        }

    }
}
